package com.atguigu.gmall.product.component;

import org.apache.ibatis.cache.Cache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 1、真正整合MyBatis需要自己创建客户端，然后连接操作redis
 */
@Component
public class MyBatisCache implements Cache {

    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Override
    public String getId() {
        return null;
    }

    @Override
    public void putObject(Object o, Object o1) {
        stringRedisTemplate.opsForValue().set(o.toString(),o1.toString());
    }

    @Override
    public Object getObject(Object o) {

        return stringRedisTemplate.opsForValue().get(o.toString());
    }

    @Override
    public Object removeObject(Object o) {
        return stringRedisTemplate.delete(o.toString());
    }

    @Override
    public void clear() {
//        stringRedisTemplate.f
    }

    @Override
    public int getSize() {
        return 0;
    }
}